<?php

require_once('custom-menu.php');
/**
 * Codeshore team dev
 */
// hide adminbar on front-end
show_admin_bar(false);

//signsnow_setup
if (!function_exists('signsnow_setup')) :

  function signsnow_setup() {
    add_theme_support('post-formats', array(
        'aside', 'image', 'video', 'audio', 'quote', 'link', 'gallery',
    ));
    // This theme uses wp_nav_menu() in two locations.
    register_nav_menus(array(
        'primary' => __('Top primary menu', 'Signsnow')
    ));

    load_theme_textdomain('signsnow', get_template_directory() . '/languages');

    // Enable support for Post Thumbnails, and declare two sizes.
    add_theme_support('post-thumbnails');
  }

endif; // signsnow_setup
add_action('after_setup_theme', 'signsnow_setup');

//register widget function
function signsnow_widgets_init() {
  //Top widget register
  register_sidebar(array(
      'name' => __('Top Body', 'Signsnow'),
      'id' => 'top-area',
      'description' => __('Top Body that appears on the content.', 'Signsnow'),
      'before_widget' => '<div class="region animated-area"><div class="container">',
      'after_widget' => '</div></div>',
      'before_title' => '<h2 class="title-big">',
      'after_title' => '</h2>',
  ));

  //Footer Left register
  register_sidebar(array(
      'name' => __('Left Footer', 'Signsnow'),
      'id' => 'left-footer',
      'description' => __('Left Footer that appears on the footer.', 'Signsnow'),
      'before_widget' => '',
      'after_widget' => '',
      'before_title' => '<div class="title">',
      'after_title' => '</div>',
  ));

  //Footer Midle register
  register_sidebar(array(
      'name' => __('Midle Footer', 'Signsnow'),
      'id' => 'midle-footer',
      'description' => __('Midle Footer that appears on the footer.', 'Signsnow'),
      'before_widget' => '',
      'after_widget' => '',
      'before_title' => '<div class="title">',
      'after_title' => '</div>',
  ));

  //Footer Right register
  register_sidebar(array(
      'name' => __('Right Footer', 'Signsnow'),
      'id' => 'right-footer',
      'description' => __('Right Footer that appears on the footer.', 'Signsnow'),
      'before_widget' => '',
      'after_widget' => '',
      'before_title' => '<div class="title">',
      'after_title' => '</div>',
  ));

  //Copy right register
  register_sidebar(array(
      'name' => __('Copyright Footer', 'Signsnow'),
      'id' => 'copyright-footer',
      'description' => __('Copyright Footer that appears on the bottom footer.', 'Signsnow'),
      'before_widget' => '',
      'after_widget' => '',
      'before_title' => '<div class="title">',
      'after_title' => '</div>',
  ));

  //sidebar register
  register_sidebar(array(
      'name' => __('Side Bar', 'Signsnow'),
      'id' => 'side-bar',
      'description' => __('sidebar that appears on the right content.', 'SignsnowSignsnow'),
      'before_widget' => '<div class="widget">',
      'after_widget' => '</div></div>',
      'before_title' => '<h2 class="widget-title">',
      'after_title' => '</h2><div class="widget-content">',
  ));
}

add_action('widgets_init', 'signsnow_widgets_init');

//register scripts function
function signsnow_scripts() {
  // Add file import.css 
  wp_enqueue_style('imports', get_template_directory_uri() . '/common/css/import.css');

  //add file jquery to the header
  wp_enqueue_script('jquery-min', get_template_directory_uri() . '/common/js/jquery.min.js', array(), '');
  //add file bootraps-min to the header
  //wp_enqueue_script('bootraps-min', get_template_directory_uri() . '/common/js/bootstrap.min.js', array(), '');
  //add file jquery-inview to the header
  //wp_enqueue_script('jquery-inview', get_template_directory_uri() . '/common/js/jquery.inview.js', array(), '');
  //add file jquery-countTo to the header
  //wp_enqueue_script('jquery-countTo', get_template_directory_uri() . '/common/js/jquery.countTo.js', array(), '');
  //add file jquery-fractionslider to the header
  //wp_enqueue_script('jquery-fractionslider', get_template_directory_uri() . '/common/js/jquery.fractionslider.min.js', array(), '');
  //add file svg-injector to the header
  //wp_enqueue_script('svg-injector', get_template_directory_uri() . '/common/js/svg-injector.min.js', array(), '');
  //add file config-bootraps to the header
  //wp_enqueue_script('config-bootraps', get_template_directory_uri() . '/common/js/config-bootraps.js', array(), '');
  // color box
  //wp_enqueue_script('colorbox-min', get_template_directory_uri() . '/common/js/jquery.colorbox-min.js', array(), '');

  //add common file
  //wp_enqueue_script('seta-js', get_template_directory_uri() . '/common/js/common.js', array(), '');
  wp_enqueue_script('main-js', get_template_directory_uri() . '/common/js/jquery.main.js', array(), '');
  // wp_localize_script( 'seta-js', 'ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); // setting ajaxurl
}

add_action('wp_enqueue_scripts', 'signsnow_scripts');

function remove_shortcode_from_gallery($content) {
  $categories = get_the_category();
  if (in_array($categories[0]->cat_ID, array(7))) {
    $content = strip_shortcodes($content);
  }
  return $content;
}

add_filter('the_content', 'remove_shortcode_from_gallery');

//hook link to content category 4
function addlink_to_category($content) {
  $categories = get_the_category();
  $url = 'http://www.dantri.com.vn';
  if (in_array($categories[0]->cat_ID, array(4))) {
    $content .= '<a href=' . $url . '>dantri.com.vn</a>';
  }
  return $content;
}

add_filter('the_content', 'addlink_to_category');

// limit text
function word_trim($string, $count, $ellipsis = FALSE) {
  $words = explode(' ', $string);
  if (count($words) > $count) {
    array_splice($words, $count);
    $string = implode(' ', $words);
    if (is_string($ellipsis)) {
      $string .= $ellipsis;
    } elseif ($ellipsis) {
      $string .= '&hellip;';
    }
  }
  return $string;
}

function register_my_menus() {
  register_nav_menus(
    array(
      'top-header-menu' => __( 'Top Header Menu' ),
      'main-header-menu' => __( 'Main Header Menu' ),
      'footer-menu-01' => __( 'Footer Menu 01' ),
      'footer-menu-02' => __( 'Footer Menu 02' ),
      'footer-menu-03' => __( 'Footer Menu 03' )
    )
  );
}
add_action( 'init', 'register_my_menus' );

/**
 * Manage output of wp_title()
 */
function roots_wp_title($title) {
  if (is_feed()) {
    return $title;
  }

  $title .= get_bloginfo('name');

  return $title;
}
add_filter('wp_title', 'roots_wp_title', 10);
